package com.ruoyi.slope.device.sensor.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.device.sensor.domain.SlopeSensorList;
import com.ruoyi.slope.device.sensor.service.ISlopeSensorListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 传感器列表Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/device/sensor")
public class SlopeSensorListController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeSensorListService slopeSensorListService;

    /**
     * 查询传感器列表列表
     */
    @PreAuthorize("@ss.hasPermi('device:sensor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeSensorList slopeSensorList)
    {
        startPage();
        List<SlopeSensorList> list = slopeSensorListService.selectSlopeSensorListList(slopeSensorList);
        return getDataTable(list);
    }

    /**
     * 查询传感器列表列表
     */
    @PreAuthorize("@ss.hasPermi('device:sensor:list')")
    @GetMapping("/listSensorId")
    public Map<String,String> listSensorId(SlopeSensorList slopeSensorList)
    {
        slopeSensorList.setDeptId(getDeptId());
        return slopeSensorListService.selectSlopeSensorId(slopeSensorList);
    }

    /**
     * 导出传感器列表列表
     */
    @PreAuthorize("@ss.hasPermi('device:sensor:export')")
    @Log(title = "传感器列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeSensorList slopeSensorList)
    {
        List<SlopeSensorList> list = slopeSensorListService.selectSlopeSensorListList(slopeSensorList);
        ExcelUtil<SlopeSensorList> util = new ExcelUtil<SlopeSensorList>(SlopeSensorList.class);
        String path = util.exportExcel(response, list, "传感器列表数据"); 
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取传感器列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:sensor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeSensorListService.selectSlopeSensorListById(id));
    }

    /**
     * 新增传感器列表
     */
    @PreAuthorize("@ss.hasPermi('device:sensor:add')")
    @Log(title = "传感器列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeSensorList slopeSensorList)
    {
        return toAjax(slopeSensorListService.insertSlopeSensorList(slopeSensorList));
    }

    /**
     * 修改传感器列表
     */
    @PreAuthorize("@ss.hasPermi('device:sensor:edit')")
    @Log(title = "传感器列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeSensorList slopeSensorList)
    {
        return toAjax(slopeSensorListService.updateSlopeSensorList(slopeSensorList));
    }

    /**
     * 删除传感器列表
     */
    @PreAuthorize("@ss.hasPermi('device:sensor:remove')")
    @Log(title = "传感器列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeSensorListService.deleteSlopeSensorListByIds(ids));
    }
}
